﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Modles.DTO;
using Modles.Models;

namespace BilbilDAL
{
    public class CarouselTwoDAL
    {
        public List<Carousel_DTO> GetCarouselTwo()
        {
            using (VideoPlatformDbContext db = new VideoPlatformDbContext())
            {
                IQueryable<Carousel_DTO> query = from a in db.CarouselTwos
                                                 join b in db.Images on a.ImageId equals b.Id
                                                 select new Carousel_DTO
                                                 {
                                                     Id = a.Id,
                                                     ImageId = a.ImageId,
                                                     Address = b.Address,
                                                     Description = b.Description
                                                 };
                return query.ToList();
            }
        }
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="ImageId"></param>
        /// <returns></returns>
        public bool AddCarouselTwo(int ImageId)
        {
            using (VideoPlatformDbContext com = new VideoPlatformDbContext())
            {
                com.CarouselTwos.Add(new CarouselTwo() { ImageId = ImageId });
                if (com.SaveChanges() > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool DeleteCarouselTwo(int Id)
        {
            using (VideoPlatformDbContext com = new VideoPlatformDbContext())
            {
                CarouselTwo carousel = com.CarouselTwos.Find(Id);
                if (carousel == null) { return false; }
                com.CarouselTwos.Remove(carousel);
                if (com.SaveChanges() > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}
